<template>
	<div>
		<view class="wrap">
			<image class="icon" src='/static/images/cashier_logo.png' />
			
			<view class="title">
				订单已提交，请尽快付款!
			</view>
			
			<view class="time">
				倒计时{{minute}}分{{second}}后订单将失效。
			</view>
			
			<view class="line"></view>
			
			<view class="num-bg order-item">
				<view class="left">
					订单编号
				</view>
				
				<view class="right">
					{{dataInfo.localNo}}
				</view>
			</view>
			
			<view class="order-item price-bg">
				<view class="left">
					付款金额
				</view>
				
				<view class="right price">
					¥{{dataInfo.price}}
				</view>
			</view>
			
			<view class="btn" @click="onPay">
				前往付款
			</view>
		</view>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				dataInfo: null, //数据
				downTimer: null, //倒计时
				minute: '', //分
				second: '', //秒
				totalTime: 0, //总时间
			}
		},
		onLoad(options) {
			if (options.data) {
				this.dataInfo = JSON.parse(options.data);
				this.totalTime = parseInt(this.dataInfo.cancelDuration)
				this.downCount()
				this.downTimer = setInterval(() => {
					this.downCount()
				}, 1000)
			}
		},
		onUnload() {
			clearInterval(this.downTimer);
		},
		methods: {
			/**
			 * 倒计时
			 */
			downCount() {
				if (this.totalTime < 0) {
					clearInterval(this.downTimer);
					this.$st.show("支付时间已过", () => {
						uni.navigateBack()
					})
					return;
				} 
				
				this.second = this.totalTime % 60;
				this.minute = Math.floor(this.totalTime / 60);
				
				this.totalTime--;
			},
			/**
			 * 付款
			 */
			onPay() {
				this.$filters.onWeixinPay(this.dataInfo.config, () => {
					uni.navigateBack()
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: white;
	}
	.wrap {
		width: 100%;
		overflow: hidden;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 90rpx 0;
		
		.icon {
			width: 150rpx;
			height: 150rpx;
		}
		
		.title {
			margin-top: 40rpx;
			color: #333333;
			font-size: 30rpx;
			font-weight: bold;
		}
		
		.time {
			margin-top: 20rpx;
			color: #666666;
			font-weight: 500;
		}
		
		.line {
			margin-top: 90rpx;
			width: 100%;
			height: 2rpx;
			background-color: #E5E5E5;
		}
		.num-bg {
			margin-top: 90rpx;
		}
		.price-bg {
			margin-top: 40rpx;
		}
		.order-item {
			width: 650rpx;
			overflow: hidden;
			display: flex;
			align-items: center;
			justify-content: space-between;
			
			.left {
				color: #333333;
				font-size: 28rpx;
			}
			.right {
				color: #333333;
				font-size: 28rpx;
			}
			.price {
				color: #D3362F !important;
			}
		}
		
		.btn {
			margin-top: 90rpx;
			width: 650rpx;
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			border-radius: 44rpx;
			overflow: hidden;
			color: white;
			background-color: #EA5520;
			font-size: 30rpx;
		}
	}
	
	view {
		line-height: 1;
	}
</style>